package com.mini.repository;

import com.mini.model.BusinessRangeInfo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;

/**
 * @author: zhaocg
 * @created: 2020/12/02 11:55
 */
@Repository
public interface BusinessRangeInfoRepository extends JpaRepository<BusinessRangeInfo, Long>, JpaSpecificationExecutor<BusinessRangeInfo> {

    Long countByBusinessGroupId(Long groupId);

    List<BusinessRangeInfo> findTop2ByBusinessGroupIdOrderByCreateTimeDesc(Long groupId);

    @Modifying
    @Query("delete from BusinessRangeInfo rangeInfo where rangeInfo.businessGroupId = :groupId")
    void deletedByGroupId(@Param("groupId") Long groupId);

}
